// run: $exec < input
// opt: 0
// flag: -g
#include <iostream>
#include <queue>
#include <vector>
#include <unordered_set>

int const maxn = 100;
int post[maxn];
int in[maxn];
int n, tot;

std::vector<std::vector<int>> tree(maxn);

void add_edge(int u, int v)
{
	//std::cerr << u << ' ' << v << '\n';
	tree[u].push_back(v);
}

void pre_order(int l, int r, int ll, int rr, int pr) // l, r for post
{
	if (l > r || ll > rr) return;
	if (l == r || ll == rr) { add_edge(pr, post[l]); return; }
	int root = r;
	add_edge(pr, post[root]);
	int root2 = ll;
	for (; root2 <= rr; root2++) if (in[root2] == post[root]) break;
	std::unordered_set<int> left;
	for (int i = ll; i < root2; i++) left.insert(in[i]);
	int mid = l;
	for (; mid <= r; mid++) if (left.find(post[mid]) == left.end()) break;
	pre_order(l, mid - 1, ll, root2 - 1, post[root]);
	pre_order(mid, r - 1, root2 + 1, rr, post[root]);
}

bool first = true;

void print(int u)
{
	if (first) {
		std::cout << u;
		first = false;
	} else std::cout << ' ' << u;
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n;
	for (int i = 1; i <= n; i++) std::cin >> post[i];
	for (int i = 1; i <= n; i++) std::cin >> in[i];
	pre_order(1, n, 1, n, 0);

	std::queue<int> q;
	q.push(0);
	while (!q.empty()) {
		int now = q.front(); q.pop();
		for (auto i : tree[now]) {
			q.push(i);
			print(i);
		}
	}
	std::cout << '\n';
}

